# This file is used by cmake. This file contains all definitions global to hsl. 

set( CMAKE_VERBOSE_MAKEFILE 1 )

# Compiler options

IF(UNIX) 
    # ASSUMING USING G++-4 ON LINUX
    #
    # add definition -pg for using gprof for profiling
    
    ADD_DEFINITIONS(-g3 -Wall -fPIC -Werror -pedantic --std=c++0x) # -Wextra cannot be used because of warnings in TBB
    
    #SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -pg)
    # now, supressing certain warnings
    
    ADD_DEFINITIONS(-Wno-long-long -Wno-deprecated -Wno-variadic-macros) 
    
    # no-long-long suppress the warning related to long long -- is needed for TBB; 
    # no-ignored-qualifiers suppresses the warning related to "type qualifiers ignored 
    #       on function return type" -- is needed for boost/ptr_container.h. 
    # no-deprecated suppressed the warning related to "deprecated header" -- is needed for boost;
    # no-variadic-macros suppressed the warning related to "variadic macros" -- is needed for wxWidgets;
    #
    # Note that in the future, these warnings may not need to be suppressed as the libraries mature.
    
    # Finding needed libraries
    #
    # Building and Finding the TBB Library
    
    SET(TBB_ROOT_DIR "${CMAKE_SOURCE_DIR}/thirdparty/tbb/tbb20_20080408oss_src")    
    EXECUTE_PROCESS(COMMAND "bash" "-c"  "find . -name libtbb_debug.so | cut -f 3 -d / | tr -d '\n'" WORKING_DIRECTORY ${TBB_ROOT_DIR} OUTPUT_VARIABLE TBB_OUT)
    MESSAGE("TBB_OUT is " ${TBB_OUT} ".") 
    SET(TBB_LIB_DIR "${TBB_ROOT_DIR}/build/${TBB_OUT}")
ELSEIF (WIN32)
    # ASSUMING USING VISUAL STUDIO 9 ON WINDOWS
    #
    
    ADD_DEFINITIONS(/W4)
    ADD_DEFINITIONS(/we4100) # error: unreferenced formal parameter
    ADD_DEFINITIONS(/we4101) # error: 'identifier' : unreferenced local variable
    ADD_DEFINITIONS(/we4150) # error: deletion of pointer to incomplete type 'type'; no destructor called
    ADD_DEFINITIONS(/we4189) # error: variable initialized by not referenced
    ADD_DEFINITIONS(/we4172) # error: returning address of local variable or temporary
    ADD_DEFINITIONS(/we4019) # error: A semicolon at global scope is not preceded by a statement.
    ADD_DEFINITIONS(/wd4512) # disable: 'class' : assignment operator could not be generated
    
    # Finding needed libraries
    #
    # Building and Finding the TBB Library
    
    SET(TBB_LIB_DIR "${CMAKE_SOURCE_DIR}/thirdparty/tbb/tbb20_20080408oss_src/ia32/vc9/lib")
    SET(TBB_BIN_DIR "${CMAKE_SOURCE_DIR}\\thirdparty\\tbb\\tbb20_20080408oss_src\\ia32\\vc9\\bin")
ENDIF ()


ADD_DEFINITIONS(-DDEBUG -D_UNICODE -DUNICODE) 

SET(TBB_LIB_NAME tbb_debug)
SET(TBBMALLOC_LIB_NAME tbbmalloc_debug)

FIND_LIBRARY(TBBSHARED NAMES ${TBB_LIB_NAME} PATHS ${TBB_LIB_DIR})
IF(TBBSHARED)
    MESSAGE("Found Tbb at ${TBBSHARED} in ${TBB_LIB_DIR}.")
ELSE(TBBSHARED)
    IF(UNIX)
        MESSAGE("Please run make under thirdparty/tbb/tbb20_20080408oss_src/ and try again")
    ENDIF()
        MESSAGE(FATAL_ERROR "Could not find ${TBB_LIB_NAME} in ${TBB_LIB_DIR}.")
ENDIF(TBBSHARED)
    
FIND_LIBRARY(TBBMALLOC_SHARED NAMES ${TBBMALLOC_LIB_NAME} PATHS ${TBB_LIB_DIR})
IF(TBBMALLOC_SHARED)
    MESSAGE("Found Tbbmalloc at ${TBBMALLOC_SHARED}.")
ELSE(TBBMALLOC_SHARED)
    MESSAGE(FATAL_ERROR "Could not find TBBMALLOC_SHARED.") #Please run make in ${TBB_MAKE_DIR} and run cmake again")
ENDIF(TBBMALLOC_SHARED)


# setting include directories
set(INCLUDE_DIRECTORIES_LIST
    "${CMAKE_SOURCE_DIR}"
    "${CMAKE_SOURCE_DIR}/thirdparty/minisat"
    "${CMAKE_SOURCE_DIR}/thirdparty/minisat/minisat" # unable to use minisat without this; need changes in minisat TODO
    "${CMAKE_SOURCE_DIR}/thirdparty/walksat"
)

INCLUDE_DIRECTORIES(
    ${INCLUDE_DIRECTORIES_LIST}
)

# include the list of source files
INCLUDE("CMakeLists-Sources.txt")
# include the list of test files
INCLUDE("CMakeLists-Tests.txt")

